package com.atm.controller;

import com.atm.entity.dto.AccountDTO;
import com.atm.entity.dto.LoginParams;
import com.atm.service.AccountService;
import com.atm.utils.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class LoginController {

    @Resource
    private AccountService accountService;

    @PostMapping("/login")
    public Result<AccountDTO> login(@RequestBody LoginParams loginParams) {
        if (loginParams.getAccountNo() == null
                || loginParams.getPassword() == null
        ) {
            return Result.fail("输入不能为空");
        }
        if (loginParams.getAccountNo().length() >= 20
                || loginParams.getPassword().length() >= 20
        ){
            return Result.fail("卡号和密码过长");
        }

        return accountService.login(loginParams);
    }

}
